package com.invengo.testrfid.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.invengo.testrfid.R;
import com.invengo.testrfid.app.utils.CommonUtils;
import com.invengo.testrfid.app.utils.MyUIUtils;
import com.invengo.testrfid.di.component.DaggerIndexComponent;
import com.invengo.testrfid.di.module.IndexModule;
import com.invengo.testrfid.mvp.contract.IndexContract;
import com.invengo.testrfid.mvp.presenter.IndexPresenter;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import butterknife.BindView;
import butterknife.OnClick;

import static com.jess.arms.utils.Preconditions.checkNotNull;


public class IndexActivity extends BaseActivity<IndexPresenter> implements IndexContract.View {

    @BindView(R.id.btn_out)
    Button btn_export;

    @BindView(R.id.btn_test)
    Button btn_test;

    @BindView(R.id.tv_version)
    TextView tv_version;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerIndexComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .indexModule(new IndexModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_index; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {

        String version = CommonUtils.packageName(this);
        tv_version.setText("版本号：" + version);
//        mPresenter.generateDta();
    }

    @Override
    protected void onStart() {
        super.onStart();
        mPresenter.initExportCount();
    }

    @Override
    public void showLoading() {

        MyUIUtils.showProgressDia(this);
    }

    @Override
    public void hideLoading() {
        MyUIUtils.hideProgressDia(this);
    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    /**
     * 数据导出功能
     *
     * @param view
     */
    public void queryCage(View view) {

        Intent intent = new Intent(this, CheckoutDataActivity.class);
        launchActivity(intent);
    }

    /**
     * 新增笼车
     *
     * @param view
     */
    public void addCage(View view) {

        Intent intent = new Intent(this, AddCageNewActivity.class);
        launchActivity(intent);
    }

    /**
     * 集装箱验证
     *
     * @param view
     */
    public void checkCage(View view) {

        Intent intent = new Intent(this, CheckTagActivity.class);
        launchActivity(intent);
    }

    /**
     * （集装箱管理）
     *
     * @param view
     */
    public void updateCage(View view) {

        Intent intent = new Intent(this, CageManagerActivity.class);
        launchActivity(intent);
    }

    @Override
    public void neddExport(long x) {

        btn_test.setText("数据上传  （" + x + " 条未上传)");

    }

    /**
     * 数据上传
     *
     * @param view
     */
    @OnClick(R.id.btn_test)
    public void uploadCageData(View view) {

        mPresenter.uploadCageData();
    }
}
